using AutofacAopDemo.Terminal.Models;
using Castle.DynamicProxy;

namespace AutofacAopDemo.Terminal.Interceptors;

public class CustomLoggingInterceptor : IInterceptor
{
    public CustomLoggingInterceptor(IDbContext ttest)
    {
        Console.WriteLine("CustomLoggingInterceptor Ctor");
        Console.WriteLine(ttest != null);
    }

    /// <inheritdoc />
    public void Intercept(IInvocation invocation)
    {
        Console.WriteLine($"Executing {invocation.Method.Name} with parameters: " + string.Join(", ", invocation.Arguments.Select(a => a?.ToString()).ToArray()));

        // Invoke the method
        invocation.Proceed();

        Console.WriteLine($"Finished executing {invocation.Method}");
    }
}